<?php
/**
 * Yii view form
 *
 * @author <KTD SOFT>
 * @since Jan 11, 2013 - 2:46:02 PM
 */
?>
<div class="row-fluid">
    <ul class="tab-menu nav nav-tabs tabs-main" id="myTab">
        <li class="active">
            <a data="#index_tab" class="tab-control">
                <?php echo Yii::t('post', 'Product'); ?>

            </a>
        </li>
        <li>
            <a data="#seo_tab" class="tab-control">
                <?php echo Yii::t('post', 'SEO') ?>
            </a>
        </li>
        <div class="clear"></div>
    </ul>
    <div id="index_tab" class="project_tab">
        <?php
        $this->beginWidget('MyActiveForm', array(
            'model'   => $this->model,
            'title'   => $this->pageTitle,
            'columns' => array(
                array(
                    'field'       => 'name',
                    'htmlOptions' => array('class' => "span10"),
                ),
                array(
                    'field' => 'c_id',
                    'type'  => 'dropDownList',
                    'data'  => Category::getPublicArray(),
                ),
                array(
                    'field' => 'price',
                ),
                array(
                    'field'       => 'address',
                    'type'        => 'textArea',
                    'htmlOptions' => array('class' => "span6"),
                ),
                array(
                    'field'       => 'description',
                    'type'        => 'textArea',
                    'htmlOptions' => array('class' => "span10"),
                ),
                array(
                    'field' => 'content',
                    'type'  => 'editor',
                ),
                array(
                    'field' => 'image',
                    'type'  => 'image',
                ),
                array(
                    'field' => 'rank',
                ),
                array(
                    'field'       => 'type',
                    'type'        => 'dropDownList',
                    'data'        => Product::getArrayType(),
                    'htmlOptions' => array('class' => ""),
                ),
                array(
                    'field'       => 'google_index',
                    'type'        => 'dropDownList',
                    'data'        => Product::getArrayGoogle(),
                    'htmlOptions' => array('class' => ""),
                ),
                array(
                    'field'       => 'status',
                    'type'        => 'dropDownList',
                    'data'        => Product::getArrayStatus(),
                    'htmlOptions' => array('class' => ""),
                ),
            ),
        ));
        ?>
        <div class="clear"></div>
        <!--        <ul id="myTab" class="nav nav-tabs tabs-main">    
                    <li class="active">
                        <a href="#picture" data-toggle="tab">
        <?php echo Yii::t('sub_all', 'Picture') ?>
                        </a>
                    </li>
                </ul>
                <div class="clearfix"></div>-->
        <!--        <div id="myTabContent" class="tab-content tabs-main-content padding-null">    
                    <div class="tab-pane tab-overflow-main fade in active" id="picture">
                        <div class="content">
        <?php
//                    if (!empty($this->model->productImage))
//                        foreach ($this->model->productImage as $picture)
//                        {
//                            $this->renderPartial('meta', array(
//                                'model' => $picture,
//                                'upload' => TRUE,
//                                'type' => 'picture',
//                            ));
//                        }
        ?>
                            <a href="#" onclick="return add_file_upload($(this), 'picture', true)" class="btn">
                                <i class="icon icon-plus"></i> Thêm
                            </a>
                        </div>
                    </div>    
                </div>-->
        <!--<div id='delItem'></div>-->
    </div>
    <div id="seo_tab" class="project_tab hide tabs-main-content padding-null">
        <div class="grid-title">
            <div class="pull-left"><?php echo $this->pageTitle ?></div>

            <div class="clear"></div>
        </div>
        <div class="grid-content">
            <div class="formRow">
                <b> <?php echo Yii::t('sub_all', 'Preview') ?> </b>
                <div class="formRight">
                    <div class="span10">
                        <a id="title_seo"  href="<?php
                        echo Yii::app()->createAbsoluteUrl('project/view', array(
                            'url'  => $this->model->url,
                            'lang' => Yii::app()->language
                        ))
                        ?>">
                               <?php echo $this->model->name ?>
                        </a>
                        <div class="url_seo">
                            <div id="original_url">
                                <?php
                                echo Yii::app()->createAbsoluteUrl('project/view', array(
                                    'url'  => $this->model->url,
                                    'lang' => Yii::app()->language
                                ));
                                ?>
                            </div>
                            <div id="change_url" class="hide">
                                <?php
                                echo Yii::app()->getBaseUrl(true) . '/' . Yii::app()->language . '/' . '<span id="url_seo"></span>.html';
                                ?>
                            </div>
                        </div>
                        <div id="meta_desc">
                            <?php
                            if ($this->model == null)
                            {
                                echo $this->model->description;
                            }
                            else
                            {
                                echo $this->model->meta_desc;
                            }
                            ?>
                        </div>
                        <div class="clear"></div>
                    </div>
                </div>
            </div>
            <div class="formRow">
                <label>
                    <?php echo Yii::t('sub_all', "Url") ?>
                </label>
                <div class="formRight">
                    <input type="text" id="Product_url" class="span10" name="Product[url]" value="<?php echo $this->model->url; ?>">
                </div>
                <div class="clear"></div>
            </div>
            <div class="formRow">
                <label>
                    <?php echo Yii::t('sub_all', "Meta Description") ?>
                </label>
                <div class="formRight">
                    <textarea id="desc" class="resize-text span10" name="Product[meta_desc]"><?php echo $this->model->meta_desc; ?></textarea>
                </div>
                <div class="clear"></div>
            </div>
            <div class="formRow">
                <label>
                    <?php echo Yii::t('sub_all', "Meta keywords") ?>
                </label>
                <div class="formRight">
                    <textarea id="desc" class="resize-text span10" name="Product[meta_keywords]"><?php echo $this->model->meta_keywords; ?></textarea>
                </div>
                <div class="clear"></div>
            </div>
            <div class="formRow">
                <label>
                    <?php echo Yii::t('sub_all', "Seo title") ?>
                </label>
                <div class="formRight">
                    <textarea id="seo_title" class="resize-text span10" name="Product[seo_title]"><?php echo $this->model->seo_title; ?></textarea>
                </div>
                <div class="clear"></div>
            </div>
        </div>
    </div>
    <div class="clear"></div>


    <?php $this->endWidget(); ?>
    <script>
        $(function () {
            $('#Product_name').keyup(function () {
                title = $('#Product_name').val();
                $('#Product_url').val(convertToSlug(title));
            });
            $('#Product_name').keyup(function () {
                title = $('#Product_name').val();
                $('#seo_title').text(title);
            });
            $('#seo_title').keyup(function () {
                title = $('#seo_title').val();
                $('#title_seo').text(title);
            });
            $('#Product_name').keyup(function () {
                title = $('#Product_name').val();
                $('#title_seo').text(title);
            });
            $('#Product_name').keyup(function () {
                title = $('#Product_title').val();
                $('#url_seo').text(convertToSlug(title));
            });
            $('#Product_url').keyup(function () {
                title = $('#Product_url').val();
                $('#url_seo').text(convertToSlug(title));
            });
            $('#Product_url').keyup(function () {
                $('#original_url').hide();
                $('#change_url').show();
            });
            $('#Product_title').keyup(function () {
                $('#change_url').removeClass('hide');
                $('#original_url').hide()();
                $('#change_url').show();
            });
            $('#desc').keyup(function () {
                title = $('#desc').val();
                $('#meta_desc').text(title);
            });
        });
        $('.tab-control').parent().click(function () {
            $('.project_tab').each(function () {
                $(this).addClass('hide');
            });

            id = $(this).children('a').attr('data');
            $(id).removeClass('hide');

            $('.tab-control').each(function () {
                $(this).parent().removeClass('active');
            });

            $(this).addClass('active');
        });

        function add_file_upload(link, type, upload)
        {
            var today = new Date();
            id = 'PM' + today.getTime();

            no_photo = "<?php echo Yii::app()->controller->asset ?>/images/no_photo.jpg";

            input_name = 'ProductMeta[' + id + ']';
            input_id = 'meta_' + id;

            meta_key = '<input type="text" name="' + input_name + '[rank]" ';
            meta_key += ' placeholder="Thứ tự" class="span11" />';
            meta_value = '<input type="hidden" name="' + input_name + '[file]" ';
            meta_value += ' placeholder="Liên kết" id="' + input_id + '" class="span12" />';
            file = '<div class="formRow">';
            file += '<div class="span10">';
            file += '<div class="span4">';
//            file += meta_key;
            file += '</div>';
            file += '<div class="span6" >';
            file += meta_value;
            if (type === 'picture') {
                file += '<img id="prv_' + input_id + '" src="' + no_photo;
                file += '" style="max-height:200px;max-width:200px" />';
            }
            file += '</div>';

            if (upload === true)
            {
                file += '<div class="span2">';
                file += '<a onclick="return upload_file(\'' + input_id + '\')" href="#" class="btn btn-primary">';
                file += '<i class="icon-upload"></i>';
                file += 'Chọn file';
                file += '</a>';
                file += '</div>';
            }

            file += '</div>';
            file += '<div class="span2">';
            file += '<a class="btn btn-inverse" onclick="del_file($(this), true)">';
            file += '<i class="icon-remove" ></i>';
            file += '<?php echo Yii::t('form', 'Delete') ?>';
            file += '</a>';
            file += '</div>';
            file += '</div>';
            file += '<div class="clearfix"></div>';

            link.before(file);
            return false;
        }

        function del_file(el, newfile)
        {
            if (newfile)
                el.parent().parent().remove();
            else
            {
                del_id = el.attr('del_id');
                input_del = '<input type="hidden" name="deleteItem[]" value="' + del_id + '" />';
                $('#delItem').after(input_del);
                el.parent().parent().remove();
            }

            return false;
        }
    </script>